package aom.example.security.mapper;


import aom.example.security.domain.SysMenuEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/11 14:40
 * @since JDK 1.8
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenuEntity> {

    @Select("<script>" +
            "   select * from (" +
            "       select a.role_id,a.menu_id,role_name,c.name,c.permission,c.menu_url,c.createTime from sys_role_menu  a " +
            "       LEFT JOIN sys_role b ON a.role_id=b.role_id LEFT JOIN " +
            "       sys_menu c ON a.menu_id=c.menu_id " +
            "   ) a" +
            "   <where>" +
            "       <if test=\"keyword !=null \">" +
            "           and role_name like CONCAT('%',#{keyword},'%')" +
            "       </if>" +
            "       <if test=\"keyword !=null \">" +
            "           or name like CONCAT('%',#{keyword},'%')" +
            "       </if>" +
            "   </where>" +
            "   order by createTime limit #{page},#{size}" +
            "</script>")
    List<Map<String, Object>> selectMenuRoleList(Map map);

    @Select("<script>" +
            "   select count(1) from (" +
            "       select a.role_id,a.menu_id,role_name,c.name,c.permission,c.menu_url,c.createTime from sys_role_menu  a " +
            "       LEFT JOIN sys_role b ON a.role_id=b.role_id LEFT JOIN " +
            "       sys_menu c ON a.menu_id=c.menu_id " +
            "   ) a " +
            "   <where>" +
            "       <if test=\"keyword !=null \">" +
            "           and role_name like CONCAT('%',#{keyword},'%')" +
            "       </if>" +
            "       <if test=\"keyword !=null \">" +
            "           or name like CONCAT('%',#{keyword},'%')" +
            "       </if>" +
            "   </where>" +
            "</script>")
    Integer selectMenuRoleListCount(Map map);
}
